Go to Robotic Automation version 22.1 documentation

Using the xmlDocumentComponent with schema

These steps show how to use the xmlDocumentComponent in StronglyTyped mode. Sample XML document and XSD Schema files are used.

 

Loading the OuterXML of an XML document

  1. Use the solution created in the Using the xmlDocumentComponent topic. Rename the solution and assign to it this name:  XML Document 1 Strongly Typed.

  2. Modify the Windows form in the solution. This form will be used to specify the name of the XML document to load, display information from the document, update node information and validate the XML. Complete the Windows form as follows:

  3. Save the solution.

  4. Copy the sample XML and XSD files to the solution folder.

    -   Pubtest.xml
    -   Pubs1d.xsd

    Depending where you save the Pubs1d.xsd file, you may need to modify the Pubtest.xml file to make sure the path to the schema is correct.

  5. Open the LoadDocument automation and select the xmlDocumentComponent from the Global tab.

  6. Click the Edit Schema Provider link in the Properties grid. The Edit Schema Provider window is displayed.

  7. Select XSD for the Select Schema Provider type.

  8. Click Browse in the Specify Schema Provider Source field. Use the Open dialog to select the Pubs1d.xsd file and then click OK. The DocumentMode automatically changes to StronglyType and the SchemaProviderType displays as XSD.

  9.  Save the solution.

 

Adding Refresh and Clear functions

This solution contains functions for updating the document nodes. The Windows form contains a Refresh button for replacing the XML shown in the txtXML text box. The form also contains a New button for creating a new document based on the schema. Use these steps to add this functionality.

  1. Open the LoadDocument automation.

  2. Add the btnRefresh Click event to the automation.

  3. Select the xmlDocumentComponent in the Global tab and add the OuterXML property for the component to the automation.

  4. Add the txtXML text box Text property to the automation and connect the components as shown below.

  5. Save the solution.

  6. Add the btnNew Click event to the automation.

  7. Select the xmlDocumentComponent in the Global tab and add the ClearDocument method and OuterXML property to the automation.

  8. Add the txtXML text box Text property to the automation and connect the components as shown below.

  9. Save and run the project.

  10. Enter the path and file name for the XML document in the File Name text box and click the Load button. The XML document text should appear in the XML text box.

  11. Click in the XML text box and enter some text to modify the XML text box contents.

  12. Click Refresh. The original XML document text should display.

  13. Click New. An empty XML document with the schema structure should appear in the text box, as shown below.

  14. Stop the project.

 

Adding an automation to validate the XML against the schema

  1. Add an automation and assign this name to it: ValidateSchema. This automation will use the xmlDocumentComponent Validate method to validate the XML loaded against the Pubs1d.xsd schema.

  2. Add the btnValidate Click method to the ValidateSchema automation.

  3. Select the xmlDocumentComponent under the LoadDocument automation in Object Explorer. Add the Validate method for the component to the ValidateSchema automation.

  4. Add a MessageDialog component and choose the (String Message): DialogResult overload. Set the message to Document Valid.

  5. Select the xmlDocumentComponent and add the ValidateErrors property to the automation.

  6. Add a ListLoop component to the automation and connect the blocks as shown below.

  7. Right-click the Item output data node of the ListLoop and select Extract Proxy. An xmlDocumentValidationErrorProxy1 is added to the automation in the Local tab and is displayed on the automation.

  8. Add the Message property for the xmlDocumentValidationErrorProxy1 to the automation.

  9. Add the Show (1 parameter) method for the MessageDialog to the automation. Complete this part of the automation as shown below.

  10. Save and run the project. Load the Pubtest.xml document and then click the Validate button. The Document Valid message is displayed. Next, load the Books.xml document which was used with the Using the xmlDocumentComponent topic. Click here to download the Books.xml file. Click the Validate button. A validation message is displayed.

  11. Click OK and stop the solution.

 

Updating publisher information

Using the Publisher Operations tab of the Windows form, the solution is used to update Publisher nodes in the XML document. These methods are used:

Follow these steps.
 

CreatePublishers

You will use the GetDocumentElement method to create an element instance for use with the Create, Append, Prepend, and Insert methods.

  1. Add a new automation to the solution and assign this name to it: UpdatePublishers.

  2. Add the btnPubXAppendChildXML Button Click event to the automation.

  3. Select the xmlDocumentComponent listed under the LoadDocument automation in Object Explorer and add the GetDocumentElement method to the automation.

  4. Right-click the Result output of the GetDocumentElement method and select Extract Proxy. The dsPubsProxy, which contains an instance of the element, is added to the automation. Connect these components as shown below.

  5. Add the xmlDocumentComponent CreatePublishers method. Data input ports are included on the CreatePublishers method for the Publishers XML node. Connect the output event from the dsPubsProxy to the CreatePublishers method as shown below.

  6. Add the Text properties for the following text boxes to the UpdatePublishers automation:

    -   txtPubID
    -   txtPubName
    -   txtPubCity
    -   txtPubState
    -   txtPubCountry
     

AppendChildPublishers

Follow these steps.

  1. Select the dsPubsProxy from the Local tab and add the AppendChildPublishers (1 parameter element) method. Note that since this is a strongly typed document, you must use the AppendChildPublishers method rather than the AppendChild method to append a child element.

  2. Complete this part of the automation by making the data and event connections shown here:

  3. Click Edit > Select All.

  4. With all of the blocks on the UpdatePublishers automation highlighted, click Automation > Group Objects. Assign this name to the group: Append Publishers. (See an example.)

  5. Save and run the solution. Load the Pubtest.xml document and then select the Publisher Info tab on the Windows form.

  6. Enter information in the PubID, Pub Name, City, State, and Country text boxes and then click the Append Child (obj) button. Click Refresh to display the updated XML in the XML text box. The new Publisher node information should appear at the end of the XML as shown below.

  7. Stop the solution.

PrependChildPublishers

To Prepend a child node to the Publishers element, the PrependChildPublishers method for the dsPubsProxy object is used. The logic required for the PrependChildPublishers method is very similar to that used for the AppendChildPublishers .Follow these steps.

  1. Select the Append Publishers group box, then click Edit > Copy.

  2. Right-click an open part of the UpdatePublishers automation and click Paste. A duplicate copy of the Append Publishers group box is displayed on the automation. Change the name of this group box to Prepend Publishers.

  3. Select the btnPubXPrependChild Click method. Drag it to the automation and drop it on top of the btnPubXAppendChild Click block. A dashed line will surround the block indicating you are replacing the block with another object, as shown below.

  4. When you release the mouse button, a confirmation message is displayed. Click Yes to replace the event.

  5. Select the dsPubsProxy in the Local tab and then select the PrependChildPublishers (1 parameter element) method. Note that since this is a strongly typed document, you must use the PrependChildPublishers method rather than the PrependChild method to add a child element.

  6. Drag and drop the PrependChildPublishers method on top of the dsPubsProxy1 AppendChildPublishers method in the Prepend Publishers group box. A dashed line will surround the block, indicating you are replacing the block with another object. When you release the mouse button, a confirmation message is displayed.

  7. Click Yes to replace the method. This part of the UpdatePublishers automation should look like the one shown below.

  8. Save and run the solution. Load the Pubtest.xml document and then select the Publisher Info tab on the Windows form.

  9. Enter information in the PubID, Pub Name, City, State, and Country text boxes and then click the Prepend Child (obj) button. Click Refresh to display the updated XML in the XML text box. The new Publisher node information should appear at the beginning of the XML, as shown below.

  10. Stop the solution.

InsertPublishers

To insert a Publishers node, you can use the InsertPublishers (2 parameters: Index, Publishers Element) method for the dsPubsProxy object. The logic required for the InsertPublishers method is very similar to that used for AppendChildPublishers and PrependChildPublishers. To complete this part of the automation, begin by selecting the Prepend Publishers group box.

  1. With the Prepend Publishers group box highlighted, select the Copy option from the Edit menu.

  2. Right-click an open part of the UpdatePublishers automation and select Paste. A duplicate copy of the Prepend Publishers group box is displayed in the automation. Since a new block for the InsertPublishers Index parameter will need to be added, ungroup the copy of the Prepend Publishers group box by highlighting the group box and selecting Ungroup Objects from the Automation menu.

  3. Select the btnPubXInsert Click method. Drag it to the automation and drop it on top of the btnPubXPrependChild Click block. A dashed line will surround the block indicating you are replacing the block with another object as shown below.

  4. When you release the mouse button, a confirmation message is displayed. Click Yes to replace the event.

  5. Delete the dsPubsProxy PrependChildPublishers method from the automation.

  6. Select the dsPubsProxy in the Local tab and then add the InsertPublishers (2 parameters: Index, Publishers Element) method to the automation. Note that since this is a strongly typed document, you must use the InsertPublishers method rather than the Insert method to add an element.

  7. Add the txtPublisherIndex text box, Text property to the automation.

  8. Complete the automation as shown below.


     

  9. Save and run the solution. Load the Pubtest.xml document and then select the Publisher Info tab on the Windows form.

  10. Enter information in the PubID, Pub Name, City, State, and Country text boxes. Enter a number in the Index text box and then click the Insert (index, obj) button. Click Refresh to display the updated XML in the XML text box. The new Publisher node information should appear at the designated position in the XML. An example is shown here:

  11. Stop the solution.

 

Part V: Updating the New XML Document

By using the AppendChildPublishers and PrependChildPublishers methods, you can add nodes to a blank, new XML document. Follow these steps.

  1. Run the solution.

  2. Click New. XML is displayed in the XML text box based on the Pubs1d.xsd schema.

  3. Enter information in the PubID, Pub Name, City, State, and Country text boxes, and then click the Append Child (obj) button. Click Refresh to display the updated XML text in the XML text box. The new Publisher node information should appear in the XML text box. An example is shown here:



     

Related information

xmlDocumentComponent

xmlElementComponent

Using the xmlDocumentComponent

 


Privacy | Trademarks | Terms of Use | Feedback

Updated: 28 March 2024

© 2016 - 2024 Pegasystems Inc.  Cambridge, MA All rights reserved.

 

OpenSpan data classification label